﻿namespace HuwmanCode

open System

[<AutoOpen>]
module String =
    let skip n (s:String) =
        if n >= s.Length then String.Empty
        elif n < 1 then s
        else s.Substring(n)

    let skipFromEnd n (s:String) =
        if n >= s.Length then String.Empty
        elif n < 1 then s
        else s.Substring(0, s.Length - n)

    let take n (s:String) =
        if n >= s.Length then s
        elif n < 1 then String.Empty
        else s.Substring(0, n)

    let takeFromEnd n (s:String) =
        if n >= s.Length then s
        elif n < 1 then String.Empty
        else s.Substring(s.Length - n, n)

    let join seperator (value:string[]) =
        String.Join(seperator, value)

    let split seperator (s:String) =
        s.Split([|seperator|])

    let (|Null|Empty|Whitespace|Text|) s = 
        if s = null then Null
        elif s = String.Empty then Empty
        elif s.Trim() = String.Empty then Whitespace
        else Text(s)
